/*
 * ClassFileForm.java
 *
 * Copyright (c) 2008 Teamnet. All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Teamnet.
 */

package ro.prjmanager.template.form;

import ro.prjmanager.constants.BackendConstants;

import java.io.File;

/**
 * This class is used to hold the class specific attributes that are used in files generating
 * from coresponding template
 */
public class ClassFileForm extends FormTemplate{

    //this attribute hold the root package of the generated class file
    private String rootPackage;



    //this attribute hold the java file name
    protected String javaFileName;
    //this attribute hold the relative package class tor root package
    protected String relativeToRootPackage;
    //this attribute hold the relative path class tor root path
    protected String relativeToRootPath;
    //this attrinute hold the module namespace
    private String src;
    //the fmk root package
    private String fmkPackage;
    //this attribute holds the fmk common package
    private String fmkCommonPackage;
    //this attribute holds the module namespace
    protected String module;

    public ClassFileForm() {
        super();
        this.rootPackage = bundle.getString(BackendConstants.APPLICATION_GENERAL_PACKAGE_ROOT);
        this.src=bundle.getString(BackendConstants.APPLICATION_GENERAL_SRC);
        this.fmkPackage=bundle.getString(BackendConstants.APPLICATION_FMK_PACKAGE);
        this.fmkCommonPackage=bundle.getString(BackendConstants.APPLICATION_FMK_COMMON_PACKAGE);

    }

    public String getRootPackage() {
        return rootPackage;
    }

    public void setRootPackage(String rootPackage) {
        this.rootPackage = rootPackage;
    }


    public String getJavaFileName() {
        return javaFileName;
    }

    public void setJavaFileName(String javaFileName) {
        this.javaFileName = javaFileName;
    }



     public String getRelativeToRootPackage() {
        return relativeToRootPackage;
    }

    public void setRelativeToRootPackage(String relativeToRootPackage) {
        this.relativeToRootPackage = relativeToRootPackage;
    }

    public String getRelativeToRootPath() {
        return relativeToRootPath;
    }

    public void setRelativeToRootPath(String relativeToRootPath) {
        this.relativeToRootPath = relativeToRootPath;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getSrc() {
        return src;
    }

    public void setSrc(String src) {
        this.src = src;
    }

    public String getFmkPackage() {
        return fmkPackage;
    }

    public void setFmkPackage(String fmkPackage) {
        this.fmkPackage = fmkPackage;
    }

    public String getFmkCommonPackage() {
        return fmkCommonPackage;
    }

    public void setFmkCommonPackage(String fmkCommonPackage) {
        this.fmkCommonPackage = fmkCommonPackage;
    }

    /**
     * This method outputs the complete java file path
     * @return - the complete java file path
     */
    public String getGeneratedFilePath(){
        StringBuilder sb=new StringBuilder();
//        sb.append(getBasePath());
//        sb.append(BackendConstants.PATH_SEPARATOR);
//        sb.append(getDirectoryGen());
        sb.append(BackendConstants.PATH_SEPARATOR);
        sb.append(getModule());
        sb.append(BackendConstants.PATH_SEPARATOR);
        sb.append(getSrc());
        sb.append( BackendConstants.PATH_SEPARATOR);
        String relativeRootPackage=getRootPackage();
        String relativeRootPath="";
        if(relativeRootPackage.indexOf(BackendConstants.PACKAGE_SEPARATOR)>0)
            relativeRootPath=relativeRootPackage.replace(BackendConstants.PACKAGE_SEPARATOR,
                    BackendConstants.PATH_SEPARATOR) ;
        else relativeRootPath=relativeRootPackage;

        sb.append(relativeRootPath);
        sb.append( BackendConstants.PATH_SEPARATOR) ;       

        sb.append(getRelativeToRootPath());
        sb.append( BackendConstants.PATH_SEPARATOR);



        File ff=new File(sb.toString());
        if(!ff.exists())
            ff.mkdirs();
        
        sb.append(getJavaFileName());
        sb.append(BackendConstants.JAVA_FILE_EXT);
        return sb.toString();
    }


}
